home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5221 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  982 b 

  1. Path: vixen.cso.uiuc.edu!usenet
  2. From: homer@uiuc.edu
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: How to convert char to hex in C++?
  5. Date: 3 Feb 1996 02:09:46 GMT
  6. Organization: University of Illinois at Urbana
  7. Message-ID: <4eug5a$cp8@vixen.cso.uiuc.edu>
  8. References: <DM679K.BD1@undergrad.math.uwaterloo.ca>
  9. Reply-To: n-dade@uiuc.edu
  10. NNTP-Posting-Host: homer.apr.uiuc.edu
  11. X-Newsreader: IBM NewsReader/2 v1.2
  12.  
  13. In <DM679K.BD1@undergrad.math.uwaterloo.ca>, hylo@neumann.uwaterloo.ca (Grace Hai Yan Lo) writes:
  14. >    I just wonder if anyone know how to convert a char (e.g. 'a') to
  15. >hex digit (i.e. 61 for 'a') in C++?  Somehow the cout << hex << n <<endl;
  16. >works for n being an integer but not a character.  Thanks.
  17.  
  18. char n = 'a';
  19. cout << hex << (int) n << endl;
  20.  
  21. By casting the char as an int you don't change its numerical value, but the "emit
  22. an int" method is invoked instead of the "emit a char" method, and the int is
  23. printed in hexadecimal.
  24.  
  25. -Nicolas Dade / n9rzb / nicolas-dade@uiuc.edu
  26.  
  27.